package service

import (
	"app/internal/web/conf"
	"app/internal/web/dao"
	"app/util"
	"sync"
)

var srvlock sync.Once
var srv *Service

var (
	daoErrorString     = "dao is empty"
	serviceCloseString = "service close"
	licenseFaildString = "license code faild"
)

type Service struct {
	cf  *conf.AppConf
	dao *dao.Dao
}

func NewService(conf *conf.AppConf) (s *Service) {

	s = &Service{
		cf:  conf,
		dao: dao.NewDao(conf),
	}

	return
}

func InitService(conf *conf.AppConf) {
	srvlock.Do(func() {
		srv = NewService(conf)
	})
}

func GetServiceInstance() *Service {
	return srv
}

func (s *Service) Close() {
	util.Info(serviceCloseString)
	s.dao.Close()
}
